package com.link2room;

import com.link2room.base.facade.IMappingServiceCacheFacadeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 加载mappingDescription信息到redis中
 * Created by LN on 2016/8/25.
 */
@Component
public class MappingRedisStartupRunner implements CommandLineRunner {

    @Resource
    private IMappingServiceCacheFacadeService mappingServiceCacheFacadeService;
    private static Logger logger = LoggerFactory.getLogger(MappingRedisStartupRunner.class);
    @Override
    public void run(String... strings) throws Exception {
        logger.info("###加载MappingDescription###");
        mappingServiceCacheFacadeService.cache();
    }


   /* private void setMappingServiceHost()throws Exception{
        MappingServiceHost ms = new MappingServiceHost();
        long count = commonDao.getCount(MappingServiceHost.class, CriteriaUtil.getCriteriaAllEQ(ms), null);
        if(count == 0){
            return;
        }else{
            long size =  count/50;
            for(int i = 0; i <= size ; i ++){
                QueryResult<MappingServiceHost> res = commonDao.findAll(MappingServiceHost.class, CriteriaUtil.getCriteriaAllEQ(ms), i * 50 , i * 50 + 99, null, null);
                if(res.getResultlist() != null && res.getResultlist().size() != 0){
                    List<MappingServiceHost> mdList = res.getResultlist();
                    for(int j = 0 ; j < mdList.size() ; j++){
                        ms = mdList.get(j);
                        redisUtil.set(ms.getServiceType(),ms.getValue());
                    }
                }
            }
        }
    }*/
}
